<template>
	<view class="" v-if="sorf">
		<block v-if="code==0||code==1||code==2">
			<view class="content">
			<block v-if="code==0">
				<view class="status_content">
					<image src="../../static/images/wait.png" mode=""></image>
					<view class="point_out">{{msg}}</view>
					<view class="flex_layout status_btn">
						<button class="status_btn1" @click="returnIndex">返回首页</button>
					</view>
				</view>
			</block>
			<block v-if="code==1">
				<view class="status_content">
					<image src="../../static/images/success.png" mode=""></image>
					<view class="point_out">{{msg}}</view>
					<view class="flex_layout status_btn">
						<button class="status_btn1" @click="returnUser">返回首页</button>
					</view>
				</view>
			</block>
			<block v-if="code==2">
				<view class="status_content">
					<image src="../../static/images/fail.png" mode=""></image>
					<view class="point_out">{{msg}}</view>
					<view class="cause">{{reason}}</view>
					<view class="flex_layout status_btn">
						<button class="status_btn1" @click="returnIndex">返回首页</button>
						<button class="status_btn2" @click="againBtn">重新提交</button>
					</view>
				</view>
			</block>
			</view>
		</block>
		<block v-else>
			<view class="addMessage_item flex_layout">
				<view class="left_name">真实姓名</view>
				<view class="right_input"><input type="text" v-model="nametext" placeholder="请输入真实姓名" placeholder-style="color: #999" value="" /></view>
			</view>
			<view class="add_btn">
				<button type="default" @click="newAppointment">提交</button>
			</view>
		</block>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				coupon_clinic_id:'',
				nametext:'',
				code:'',
				msg:'',
				reason:'',
				sorf:false
			}
		},
		onLoad(option) {
			this.coupon_clinic_id=option.clinic_id
			this.isClinicApply()
		},
		methods: {
			//等待审核结果状态，审核失败状态跳转
			returnIndex: function(){
				uni.navigateTo({
					url:'../index/index'
				})
			},
			//审核成功状态跳转
			returnUser: function(){
				uni.navigateTo({
					url:'user'
				})
			},
			//审核失败状态重新提交
			againBtn: function(){
				this.code=3
			},
			isClinicApply: function(){
				console.log('dianjiekou');
				var that=this;
				this.sorf=false;
				var data=[];
				data['coupon_clinic_id']=that.coupon_clinic_id
				that.$common.loadToShow()
				that.$api.isClinicApply(
					data,
					res => {
						if(res.code==1){
							this.sorf=true;
							that.$common.loadToHide();
							console.log(res)
							that.code=res.data.code
							that.reason=res.data.reason
							//判断是否提交信息
							if (res.data.code == 0||res.data.code == 1||res.data.code == 2) {
								that.msg=res.msg
							}
						}
						if(res.code==0){
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 2000
							})
						}

					}
				)
			},
			
			newAppointment(){
				var that=this;
				if(that.nametext==''){
					uni.showToast({
						title: '请填写真实姓名',
						icon: 'none',
						duration: 2000,
					})
				  return false; 
				}
				that.$common.loadToShow()
				var data=[];
				data['coupon_clinic_id']=that.coupon_clinic_id
				data['nametext']=that.nametext
				that.$api.subClinicApply(
					data,
					res => {
						that.$common.loadToHide();
						console.log(res)
						if (res.code == 1) {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 1000
							})
							that.isClinicApply()
						}
						if (res.code == 0) {
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 2000
							})
						}
					}
				)
			}
		}
	}
</script>

<style>
	view{box-sizing: border-box;}
	.flex_layout{display: flex; align-items: center; flex-wrap: wrap;}
	.addMessage_item{padding: 50upx 30upx; border-bottom: 1px solid #f2f2f2;}
	.left_name{color: #333; font-size: 30upx; width: 120upx;}
	.right_input{width: 570upx; padding-left: 50upx;}
	.right_input text{display: block; color: #333; font-size: 30upx;}
	.right_input input{color: #333; font-size: 30upx;}
	.otherCheck{color: #999; font-size: 30upx;}
	.otherCheck_color{color: #333;}
	.lableBox{justify-content: space-between;}
	.lableBox_img image{width: 13upx; height: 23upx;}
	.add_btn{padding: 30upx; margin-top: 30upx; justify-content: space-around;}
	.add_btn button{height: 74upx; width: 100%; font-size: 36upx; color: #fff; margin: 0; padding: 0; line-height: 74upx; background: #2562a1; border-radius: 10px;}
	.add_btn button.pass_through{width: 40%;}
	.add_btn button.noPass_through{width: 40%; border: 1px solid #2562a1; color: #2562a1; background: none;}
	.effectiveDate{color: #999; font-size: 24upx; padding: 15upx 30upx;}
	
	.content{padding: 50upx 30upx;}
	.status_content{background: #fff; border-radius: 10px; padding: 50upx 0;}
	.status_content image{width: 200upx; height: 200upx; display: block; margin: 0 auto;}
	.point_out{color: #333; font-size: 32upx; text-align: center; margin-top: 90upx;}
	.cause{color: #999; font-size: 26upx; text-align: center; margin-top: 20upx;}
	.status_btn{justify-content: center; width: 460upx; margin: 50upx auto 0;}
	.status_btn button{width: 180upx; height: 55upx; line-height: 55upx; margin: 0 20upx; padding: 0; font-size: 24upx; border-radius: 55upx;}
	.status_btn button.status_btn1{background: #2562a1; color: #fff;}
	.status_btn button.status_btn2{background: #fff; color: #2562a1; border: 1px solid #2562a1;}
</style>
